package com.pro.meeting.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pro.meeting.bean.MeetingGrab;
import com.pro.meeting.bean.MeetingPub;
import com.pro.meeting.bean.UtilsBean;
import com.pro.meeting.service.MeetingGrabService;
import com.pro.meeting.service.MeetingPubService;

@Controller
@RequestMapping("meetingGrab")
public class MeetingGrabController {
	@Autowired
	MeetingPubService meetingPubService;
	@Autowired
	MeetingGrabService meetingGrabService;
	
	/*
	 * 会议抢单列表
	 */
	@ResponseBody
	@RequestMapping("getGrabList")
	public List<MeetingPub> getGrabList(@RequestParam("uid")String uid,
			@RequestParam("type")String type){
		MeetingPub meetingPub=new MeetingPub();
		meetingPub.setUid(uid);
		meetingPub.setTitle(type);
		List<MeetingPub>  list=meetingPubService.getMyGrabByUid(meetingPub);
		System.out.println(list);
		return list;
	}
	/*
	 * 添加 会议抢单
	 */
	@RequestMapping("add")
	public String add(MeetingGrab grab){
		int num=meetingGrabService.add(grab);
		//回到抢单列表
		return "/pages/weixin/meetingGrab/meetingGrab_list.jsp?uid="+grab.getUid()+"&rid=2";
	}
	/*
	 * 我的抢单列表
	 */
	@ResponseBody
	@RequestMapping("getMyGrabList")
	public List<MeetingPub> getMyGrabList(@RequestParam("uid")String uid){
		List<MeetingPub> list=meetingPubService.getMyGrabListByUid(uid);
		return list;
	}
	
	//会议发布-- 我的发单--》选择讲者
	@ResponseBody
	@RequestMapping("getGrabListByPid")
	public List<MeetingGrab> getGrabListByPid(@RequestParam("pid")String pid){
		List<MeetingGrab> list=meetingGrabService.getGrabListByPid(pid);
		return list;
	}
	//会议发布--我的发单--》选择讲者--》就选你
	@ResponseBody
	@RequestMapping("chooseGrabStatus")
	public String chooseGrabStatus(@RequestParam("pid")String pid,
			@RequestParam("gid")String gid){
		int num=meetingGrabService.updateChooseGrabStatus(pid, gid);
		return ""+num;
	}
	
	//发单排行榜
	@RequestMapping("meetingPubRank")   //  meetingGrab/meetingPubRank
	public ModelAndView meetingPubRank(){
		List<UtilsBean> rankList=meetingGrabService.readRankBean();
		
		ModelAndView model=new ModelAndView();
		model.setViewName("/pages/weixin/rank/meetingPubRank.jsp");
		model.addObject("rankList", rankList);//将rankList存到request作用域中
		return model;
	}
	
}
